using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ReactiveLang
{
    [TestClass]
    public class StateChangeTests
    {
        [TestMethod]
        public void VariableListeningTest()
        {
            var v = new Variable<int>();

            int actual = -1;
            var valueProp = typeof(Variable<int>).GetProperty("Value");
            Expression.Member(valueProp, new [] {Expression.Constant(v).Box()}, a => ((Variable<int>)a[0]).Value).Activate(
                x => actual = x
                );

            Assert.AreEqual(v.Value, actual);
            v.Value++;
            Assert.AreEqual(v.Value, actual);
        }
    }
}